package com.galaxy.samson.staff.dao;

import com.galaxy.samson.staff.domain.Staff;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: madasamy
 * Date: 2/12/12
 * Time: 3:35 PM
 * To change this template use File | Settings | File Templates.
 */
public class StaffIDao implements IStaffDao
{
    @PersistenceContext
    private EntityManager entityManager;
    @Override

    public void create(Staff staff)
    {
        entityManager.persist(staff);
    }

    @Override
    public List<Staff> findAll()
    {
        Query query = entityManager.createQuery("select a from Staff a"); 
        return query.getResultList();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void removeAll() 
    {
        Query query = entityManager.createQuery("delete from Staff") ;
        query.executeUpdate();
    }

    @Override
    public void remove(String name) 
    {
        Query query = entityManager.createQuery("delete from Staff a where a.name = :name");
        query.setParameter("name",name);
        query.executeUpdate();
    }
}
